#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct tem{

	int a;
	char *name;
};

int main(){

	FILE *fp;
	struct tem data1[] = {{666,"Zxl"},{888,"as"}};
	struct tem data2[] = {0};

//      FILE *fopen(const char *pathname, const char *mode);
	fp = fopen("./file2","w+");
	if(fp == NULL){
		printf("filed to open file\n");
	}

//       size_t fwrite(const void *ptr, size_t size, size_t nmemb,FILE *stream);
	int n_write = fwrite(data1,sizeof(struct tem),2,fp);
	printf("write %d btye to file\n",n_write);

//	size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
	fseek(fp,0,SEEK_SET);	
	int n_read = fread(data2,sizeof(struct tem),2,fp);
	printf("data2[0].a = %d,data2[0].name = %s\n",data2[0].a,data2[0].name);
	printf("data2[1].a = %d,data2[1].name = %s\n",data2[1].a,data2[1].name);
	fclose(fp);

	return 0;
}
